package com.tanhua.controller;

import com.tanhua.service.AdminService;
import com.tanhua.vo.UserHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

@RestController
@RequestMapping(value = "/system")
public class AdminController {

    @Autowired
    private AdminService adminService;

    @GetMapping(value = "users/verification", name = "获取验证码图片")
    public ResponseEntity verification(String uuid, HttpServletResponse response) throws IOException {
        return adminService.verification(uuid, response);
    }

    @PostMapping(value = "/users/login", name = "登录")
    public ResponseEntity login(@RequestBody Map<String, String> map) throws IOException {
        String username = map.get("username");  //账号
        String password = map.get("password");  //密码
        String verificationCode = map.get("verificationCode"); //验证码
        String uuid = map.get("uuid"); //redis的验证码key
        return adminService.login(username, password, verificationCode, uuid);
    }
    @PostMapping(value = "/users/profile", name = "获取用户信息")
    public ResponseEntity profile() throws IOException {
        return adminService.profile();
    }
    @PostMapping(value = "/users/logout", name = "获取用户信息")
    public ResponseEntity logout() throws IOException {
        return adminService.logout();
    }

}
